package kz.pompei.oneGwtStands.client.remote.fake;

import java.util.List;
import java.util.Set;

import kz.pompei.OneGwt.cmodel.PersonDetails;
import kz.pompei.OneGwt.cmodel.PersonRecord;
import kz.pompei.OneGwt.cmodel.SimpleRecord;
import kz.pompei.OneGwt.ifaces.util.Getter;
import kz.pompei.OneGwt.remote.PersonroleManagerServiceAsync;
import kz.pompei.oneGwtStands.client.remote.AsyncTimer;
import kz.pompei.oneGwtStands.client.remote.data.PersonroleManagerServiceData;

import com.google.gwt.user.client.rpc.AsyncCallback;

public class PersonroleManagerServiceFake implements PersonroleManagerServiceAsync {
  
  private PersonroleManagerServiceData data = PersonroleManagerServiceData.get();
  
  @Override
  public void getPersonList(AsyncCallback<List<PersonRecord>> callback) {
    AsyncTimer.execute( callback, new Getter<List<PersonRecord>>() {
      @Override
      public List<PersonRecord> get() {
        return data.getPersonList();
      }
    } );
  }
  
  @Override
  public void getRoleList(final String applicationId, AsyncCallback<List<SimpleRecord>> callback) {
    AsyncTimer.execute( callback, new Getter<List<SimpleRecord>>() {
      @Override
      public List<SimpleRecord> get() {
        return data.getRoleList( applicationId );
      }
    } );
  }
  
  @Override
  public void getApplicationList(AsyncCallback<List<SimpleRecord>> callback) {
    AsyncTimer.execute( callback, new Getter<List<SimpleRecord>>() {
      @Override
      public List<SimpleRecord> get() {
        return data.getApplicationList();
      }
    } );
  }
  
  @Override
  public void getPersonDetails(final String personId, AsyncCallback<PersonDetails> callback) {
    AsyncTimer.execute( callback, new Getter<PersonDetails>() {
      @Override
      public PersonDetails get() {
        return data.getPersonDetails( personId );
      }
    } );
  }
  
  @Override
  public void savePerson(final PersonDetails details, AsyncCallback<PersonRecord> callback) {
    AsyncTimer.execute( callback, new Getter<PersonRecord>() {
      @Override
      public PersonRecord get() {
        return data.savePerson( details );
      }
    } );
  }
  
  @Override
  public void getRoleIds(final String personId, final String applicationId,
      AsyncCallback<Set<String>> callback) {
    AsyncTimer.execute( callback, new Getter<Set<String>>() {
      @Override
      public Set<String> get() {
        return data.getRoleIds( personId, applicationId );
      }
    } );
  }
  
  @Override
  public void addRole(final String personId, final String applicationId, final String roleId,
      AsyncCallback<Void> callback) {
    AsyncTimer.execute( callback, new Getter<Void>() {
      @Override
      public Void get() {
        data.addRole( personId, applicationId, roleId );
        return null;
      }
    } );
  }
  
  @Override
  public void deleteRole(final String personId, final String applicationId, final String roleId,
      AsyncCallback<Void> callback) {
    AsyncTimer.execute( callback, new Getter<Void>() {
      @Override
      public Void get() {
        data.deleteRole( personId, applicationId, roleId );
        return null;
      }
    } );
  }
}
